const fs = require('fs')

const files = fs.readdirSync('./src')
const filePath = files.map(item => {
  return {
    name: item,
    path: `src/${item}/index.html`
  }
})

var content = `
<!DOCTYPE html>
<html lang="en">

<head>
  <title></title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
  </style>
</head>

<body>
  <div id="app">
  $$$
  </div>
</body>

</html>
`

var str = ["<h2>vue的一些小案例</h2>"]
str.push("<ul>")
filePath.forEach(item => {
  str.push('<li>')
  str.push(`<a href="./${item.path}">${item.name}</a>`)
  str.push('</li>')
})
str.push('</ul>')
str.push(`<p>更新于${(new Date).toLocaleDateString()}`)
str.push('</p>')

str = str.join('')

content = content.replace('$$$', str)

fs.writeFileSync('./index.html',content)
